<script lang="ts" setup>
	import { reactive, ref } from "vue";
	import {
		getCurrentInstance
	} from 'vue'
	import {
		useRouter
	} from 'uni-mini-router'
	import {
		userStore
	} from '@/pinia';
	import {
		onShow,
		onHide,
		onLoad,
		onReachBottom
	} from '@dcloudio/uni-app'
	const userStoreInfo = userStore();
	const {
		proxy,
	} = getCurrentInstance()
	const userRole = userStoreInfo.userFlag
	// console.log(userStoreInfo.userFlag);
	let router = useRouter()
	const routerLink = (e) => {
		router.push({
			name: e
		})
		console.log(123);
	}
	const changeAvatar = () => {
		uni.chooseImage({
			success: (chooseImageRes) => {
				const tempFilePaths = chooseImageRes.tempFilePaths;
				console.log(tempFilePaths);
				uni.uploadFile({
					url: proxy.$uploadUrl + proxy.$api.uploadFile,
					filePath: tempFilePaths[0],
					name: 'file',
					formData: {
						file: tempFilePaths[0],
					},
					success: (uploadFileRes) => {
						console.log(JSON.parse(uploadFileRes.data));
						if (JSON.parse(uploadFileRes.data).success) {
							avatarValue.value = JSON.parse(uploadFileRes.data).result
						}
					}
				});
			}
		});
	}
	const inputInput = (e) => {
		inputValue.value = e.detail.value
	}
	const editInfo = () => {
		proxy.$req('PUT', proxy.$api.editGysInfo, {
			id: userStoreInfo.userInfo.supplier.id,
			storeName: inputValue.value,
			storeImage: avatarValue.value,
		}).then((res) => {
			console.log(res);
			if (res.success) {
				userStoreInfo.updateUserInfo(userStoreInfo.userInfo.id)
			}
			uni.$u.toast(res.message)
		})
	}
	let inputValue = ref('')
	let avatarValue = ref('')
	onLoad(() => {
		inputValue.value = userStoreInfo.userInfo.supplier.storeName || ''
		avatarValue.value = userStoreInfo.userInfo.supplier.storeImage || '../../../../static/logo.png'
	})
</script>
<template>
	<view class="container">
		<view class="maTop">
			<view class="mal c-flex-center-center" @click="changeAvatar">
				<image :src="avatarValue" mode=""></image>
				<text>更换标志</text>
			</view>
		</view>
	</view>
	<view class="bzMoney">
		<text>店铺名称</text>
		<view class="bmr intFont r-flex-center-center">
			<input style="text-align: right;" type="text" :value="inputValue" @input="inputInput">
		</view>
	</view>
	<view class="bzMoney">
		<text>店铺ID</text>
		<view class="bmr intFont r-flex-center-center">
			<text style="margin-right: 16rpx;">{{ userStoreInfo.userInfo.supplier.memberId }}</text>
		</view>
	</view>
	<view class="subBtn" @click="editInfo">
		确认
	</view>
</template>
<style lang="scss">
	page {
		background-color: #fafafa;
	}

	view {
		box-sizing: border-box;
	}

	.container {
		width: 686rpx;
		padding: 0 30rpx;
		background: #FFFFFF;
		box-shadow: 8rpx 8rpx 32rpx 0rpx rgba(0, 0, 0, 0.04);
		border-radius: 24rpx;
		border: 2rpx solid #FFFFFF;
		margin: 30rpx auto 0;

		.maTop {
			width: 100%;
			// height: 150rpx;
			margin: 0rpx auto 0rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 30rpx 0;

			.mal {
				image {
					width: 120rpx;
					height: 120rpx;
					border-radius: 70rpx;
					margin-bottom: 20rpx;
				}

				text {
					color: #909399;
					font-size: 24rpx;
				}
			}
		}
	}

	.bzMoney {
		width: 686rpx;
		padding: 30rpx;
		margin: 30rpx auto 0;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-weight: 400;
		background: #FFFFFF;
		box-shadow: 8rpx 8rpx 32rpx 0rpx rgba(0, 0, 0, 0.04);
		border-radius: 24rpx;
		border: 2rpx solid #FFFFFF;

		.bmr {
			color: #909399;
			line-height: 30rpx;
		}
	}

	.subBtn {
		width: 686rpx;
		height: 88rpx;
		background: #CB645E;
		line-height: 88rpx;
		text-align: center;
		color: #FFFFFF;
		font-size: 32rpx;
		font-weight: 500;
		border-radius: 16rpx;
		margin-left: 24rpx;
		margin-top: 150rpx;
	}
</style>